/**
 * 
 */

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author James Chy
 *
 */
public class NoItems extends PhotoServlet {

	public static final long serialVersionUID = 999;
	
    public int getCount(String query)
    {
        //out.println("getCount query: " + query);
    	
        int count = 0;
        ResultSet rs;

        if(query!=null)
        {
            try
            {
            	rs = executeQuery(query);
                if(rs.next())
                	count = rs.getInt("COUNT(*)");
            }
            catch(SQLException sqle)
            {
                out.println("SQL Exception Error "+sqle.toString() );
            }
            catch(NullPointerException npe)
            {
            	out.println("Null Pointer Exception: " + npe);
            }
        }

        return count;
    }

    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
    }
        
	/**
	 * @param args
	 */
    public void doGet(HttpServletRequest request,
            HttpServletResponse response)
    		throws IOException, ServletException
    {
        response.setContentType("text/html");
        out = response.getWriter();
		out.println("<HTML>");
		out.println("<BODY>");
		String query = "";
		query += "select image_file from images ";
		query += "left join image_person on (image_person.image_uid = images.uid) ";
		query += "left join image_thing on (image_thing.image_uid = images.uid) ";
		query += "left join image_place on (image_place.image_uid = images.uid) ";
		query += "where image_person.image_uid is null ";
		query += "and image_thing.image_uid is null ";
		query += "and image_place.image_uid is null";

		ResultSet rs = executeQuery(query);
		
		try
		{
			while(rs.next())
			{
				
				String image_file = rs.getString("image_file");
				
           		out.println("<TABLE><TR><TD>" + image_file + "</TD></TR></TABLE>");
			}
		}
		catch(SQLException sqle)
		{
			out.println(sqle);
		}
		
		out.println("</BODY>");
		out.println("</HTML>");
		
	}

}
